import numpy as np
from functools import reduce

# 生成5个班的成绩
Scores = []
num = input("输入班级数（整数）：")
try:
    num = int(num)
    for i in range(num):
        # 生成
        Scores.append(np.random.randint(1, 101, size=(50, 3)))
    # 合并
    combineScore = reduce(lambda x, y: np.vstack((x, y)), Scores)

    print("所有成绩的shape:", combineScore.shape)

    sex = np.random.randint(0, 2, size=(combineScore.shape[0], 1))

    # 合并
    combineScore = np.concatenate([combineScore, sex], axis=1)
    print("加入性别后 所有成绩的shape: ", combineScore.shape)

    cond = combineScore[:, 3] == 1
    # 男孩取1的
    boys = combineScore[cond]
    print('boys shape:', boys.shape)
    print("男生最好成绩：", np.max(boys[:, 0:3], axis=0))
    print("男生最差成绩：", np.min(boys[:, 0:3], axis=0))
    print("男生平均成绩：", np.mean(boys[:, 0:3], axis=0))
    print("男生中位数成绩：", np.median(boys[:, 0:3], axis=0))
    print("男生各科成绩标准差：", np.std(boys[:, 0:3], axis=0))
    cond2 = cond == False
    # 女孩取不是1的
    girls = combineScore[cond2]
    print('girls shape', girls.shape)
    print("女生最好成绩：", np.max(girls[:, 0:3], axis=0))
    print("女生最差成绩：", np.min(girls[:, 0:3], axis=0))
    print("女生平均成绩：", np.mean(girls[:, 0:3], axis=0))
    print("女生中位数成绩：", np.median(girls[:, 0:3], axis=0))
    print("女生各科成绩标准差：", np.std(girls[:, 0:3], axis=0))

except Exception as e:
    print(e)
